﻿namespace DecorationSys.Models
{
    /// <summary>
    /// 接口返回值类
    /// </summary>
    public class MyJsonResult
    {
        public int Code { get; set; } = 500;

        public string Msg { get; set; } = "成功";

        public object Data { get; set; }

        public MyJsonResult()
        {
 
        }

        public MyJsonResult(int code, string msg, object data)
        {
            this.Data = data;
            this.Code = code;
            this.Msg = msg;
        }

        /// <summary>
        /// 通用性
        /// </summary>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static MyJsonResult GetResult(int code = 500, string msg = "成功", object? data = null)
        {
            return new MyJsonResult()
            {
                Code = code,
                Msg = msg,
                Data = data
            };
        }

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static MyJsonResult GetErrorResult(string msg)
        {
            return new MyJsonResult()
            {
                Code = 500,
                Msg = msg
            };
        }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static MyJsonResult GetSuccessResult(object? data = null)
        {
            return new MyJsonResult()
            {
                Code = 200,
                Msg = "成功",
                Data = data
            };
        }
    }
}
